# -*- coding: utf-8 -*-

from dataclasses import fields
from core.serializers import CustomModelSerializer
from rest_framework import serializers, status
from apps.sys.models import Dept


class DeptSerializer(CustomModelSerializer):
    """
    部门-序列化器
    """
    class Meta:
        model = Dept
        fields = "__all__"
        read_only_fields = ["id"]


class DeptTreeSelectSerializer(CustomModelSerializer):
    """
    树型菜单表的序列化器
    """
    label = serializers.CharField(source='name')

    class Meta:
        model = Dept
        fields = "__all__"
        read_only_fields = ["id"]


class DeptCreateUpdateSerializer(CustomModelSerializer):
    """
    部门管理 创建/更新时的列化器
    """

    def create(self, validated_data):
        instance = super().create(validated_data)
        instance.dept_belong_id = instance.id
        instance.save()
        return instance

    class Meta:
        model = Dept
        fields = '__all__'
